<template>
    
    <!-- 组件的模板 -->
    <div class="page user-select multi-select" v-show="searchInput.length">
        <ul class="list com-border-top com-border-bottom">
          <li class="weui-cells_checkbox" v-for="member in searchResultList">
              <label class="touch" for="{{member.user_id+'member'}}">
                  <img v-if="member.logo.thumb_url!=''" class="avatar" :src="member.logo.thumb_url">
                  <img v-if="member.logo.thumb_url==''" class="avatar" src="../../static/imgs/avatar.png">
                  <div class="info com-border-bottom" @click="selectMember(member)">
                      <p class="title"><span class="tag tag_1" v-if="member.identity_str!='成员'" 
                              :class="{'tag tag_1':member.identity_str=='管理员'||member.identity_str=='超级管理员',
                                       'tag tag_2':member.identity_str=='组长'}">{{member.identity_str}}</span>{{member.nick_name}}
                      </p>
                  </div>
              </label>
          </li>
        </ul>
      
    </div>
</template>

<script>
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */
    
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */

    import tabbar from 'vux/dist/components/tabbar'
    import cache from 'gapi/cache.js'
    import commonPage from 'clientApi/commonPage.js'
    import searchPage from 'clientApi/searchPage.js'

    /**
     *  组件实例对象
     */
    export default {
        components: {
            tabbar
        },
        data: function(){
            return{
               searchInput:'',
               searchResult:[],
               allMemberList:[]
            }
        },
        computed:{
            searchResultList(){
                let searchResultList = []
                this.allMemberList.forEach((item)=>{
                    if(item.nick_name.indexOf(this.searchInput)>-1 || item.mobile.indexOf(this.searchInput)>-1){
                        searchResultList.push(item)
                    }
                })
                return searchResultList
            }
        },
        vuex: {
            getters: {

            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){    
                cache.getMemoryCache('allMemberList', (data) => {
                    if(data){
                        this.allMemberList = data
                         console.log(this.allMemberList)
                    }
                })
                // searchPage.searchKey((data)=>{
                //     this.searchInput = data.searchKey
                // })
                window.getSearchResult=(data)=>{
                    this.searchInput = data
                }
            },
            selectMember(member) {
                cache.getMemoryCache('webViewID',(data)=>{
                    if(data){
                      commonPage.goBack(1,{'goBackKey':'submit','key':'selectMember','value':member},data.webViewID)
                    }
                })
            }
        },
        created(){
            this.init()
        }
        
    }

    
</script>

<!-- CSS 样式 -->

<style src="../../node_modules/weui/dist/style/weui.css"></style>
<style src="../../static/css/common.css"></style>
<style src="../../static/css/user-list.css"></style>